<!-- 活动详情页操作按钮 -->
<template>
  <div class="">
    <template v-for="(item, index) in buttons">
      <a-button v-if="item.show" class="_ml-10" :type="item.type || 'primary'" :key="index" @click="item.func">{{
        item.text
      }}</a-button>
    </template>

    <!-- 会员设置弹窗 -->
    <MemberSetForm ref="memberSetForm" @refresh="GetMemberInfo" />

    <!-- 退会弹窗 -->
    <RefundForm ref="refundForm" @success="GetMemberInfo" />

    <!-- 分配服务专员弹窗 -->
    <EditAttacheForm ref="attacheForm" :attacheList="serviceUserList" @success="GetMemberInfo" />

    <!-- 续费设置弹窗 -->
    <PaySetModal ref="paySetModal" />
  </div>
</template>

<script>
import MemberSetForm from '../../components/memberSetForm.vue'
import RefundForm from '../../headquarters/modules/refundForm'
import EditAttacheForm from '../../headquarters/modules/editAttacheForm'
import PaySetModal from '../../components/modal/paySet.vue'

import { SyncDataToCard } from '@/api/member/member'
import { memberRecover, getUserList, attacheList } from '@/api/system/system'

export default {
  props: ['detailInfo'],
  inject: ['GetMemberInfo'],
  components: {
    MemberSetForm,
    RefundForm,
    EditAttacheForm,
    PaySetModal,
  },
  data() {
    return {
      serviceUserList: [],
    }
  },
  computed: {
    buttons() {
      return [
        {
          text: '会员设置',
          func: () => {
            this.$refs.memberSetForm.show(this.detailInfo)
          },
          show: true,
        },
        {
          text: '续费设置',
          func: () => {
            this.$refs.paySetModal.show({
              id: this.detailInfo.memberId,
              type: 'renewSet',
            })
          },
          show: this.detailInfo.memberState !== 0,
        },
        {
          text: '服务专员管理',
          func: () => {
            this.$refs.attacheForm.show({ id: this.detailInfo.memberId, attacheUserId: this.detailInfo.attacheUserId })
          },
          show: this.detailInfo.memberState !== 0,
        },
        {
          text: '退会',
          func: () => {
            this.$refs.refundForm.show({ id: this.detailInfo.memberId, remark: '' })
          },
          show: this.detailInfo.memberState !== 0,
        },
        { text: '恢复', func: () => this.recover(this.detailInfo.memberId), show: this.detailInfo.memberState !== 1 },
      ]
    },
  },
  watch: {},
  methods: {
    //同步入会资料到名片
    handleSyncData() {
      let _this = this
      this.$confirm({
        title: '同步入会资料到名片',
        content: '确认同步后,会员资料将覆盖已有单位和个人名片信息,请谨慎操作.',
        onOk() {
          SyncDataToCard({ cocId: _this.detailInfo.memberId, leaderId: _this.detailInfo.leadingId }).then(() => {
            _this.$message.success('同步成功')
          })
        },
      })
    },
    // 恢复
    recover(id) {
      this.$confirm({
        title: `确定恢复会员吗？`,
        onOk: () => {
          memberRecover({ id: id }).then((res) => {
            if (res.code === 0) {
              this.$message.success('恢复成功!')
              this.GetMemberInfo()
            } else {
              this.$message.error(res.msg)
            }
          })
        },
        onCancel() {},
      })
    },
    async getServiceUserList() {
      let res = await attacheList({ attacheType: 'hyzy' })
      this.serviceUserList = res.data || []
    },
    handleDetail() {
      console.log('跳转详情')
    },
    handleActivityForm() {
      console.log('活动信息收集')
    },
    handleSign() {
      console.log('签到管理')
    },
  },
  created() {
    this.getServiceUserList()
  },
  mounted() {},
}
</script>
<style scoped>
</style>